package edu.yumd.bmi.action;

import edu.yumd.bmi.vo.BMIForm;
import edu.yumd.bmi.vo.Result;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class PublicAction {
    @PostMapping("getBNIValue")
    public Result getBNIValue(@RequestBody BMIForm bmiForm) throws Exception{
    Float resultf=bmiForm.getTz()/(bmiForm.getSa()*bmiForm.getSa());
    String resultstr ="";
    if (resultf<=18.4){
        resultstr="偏瘦";
    }
    else if(resultf>=18.5&&resultf<=23.9){
        resultstr="正常";
    }
    else  if (resultf>=24&&resultf<=27.9){
        resultstr="微胖";
    }
    else{
        resultstr="肥胖";
    }


        Result r=new Result();
        r.setState(resultstr);
        r.setValue(resultf);


        switch (resultstr){
            case "偏瘦":
            r.setSugguest("多吃点");
            break;
            case "正常":
            r.setSugguest("不要多吃，也不要少吃");
            break;
            case "微胖":
            r.setSugguest("少吃点");
            break;
            case "肥胖":
            r.setSugguest("绝食");
                break;
        }

    return r;
    }

}
